package name.as3.managers
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class DragManager
	{
		private var m_obTarget:Sprite ;
		private var m_fnMoveCall:Function ;
		
		/**∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥构造函数 
		 */		
		public function DragManager(obTarget:Sprite,fnMoveCall:Function )
		{
			super();
			m_obTarget = obTarget ;
			m_fnMoveCall = fnMoveCall ;
			if(obTarget!=null)
			{
				obTarget.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown_obTarget);
			}
		}
		
		/**
		 *∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥拖动启动函数 
		 * @param e
		 * 
		 */		
		private function mouseDown_obTarget(e:MouseEvent):void
		{
			m_obTarget.startDrag() ;
			m_obTarget.stage.addEventListener(MouseEvent.MOUSE_UP,mouseUp_obStage ) ;
			if(m_fnMoveCall!=null)
			{
				m_obTarget.stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMove_obStage);
			}
		}
		
		
		/**
		 *∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥指针移动函数 
		 * @param e
		 * 
		 */		
		private function mouseMove_obStage(e:MouseEvent):void
		{
			if(m_fnMoveCall!=null)
			{
				try{
					m_fnMoveCall(e) ;
				}
				catch(ex:Error)
				{
					
				}
			}
		}
		
		/**
		 *∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥拖动结束函数 
		 * @param e
		 * 
		 */		
		private function mouseUp_obStage(e:MouseEvent):void
		{
			m_obTarget.stage.removeEventListener(MouseEvent.MOUSE_UP,mouseUp_obStage ) ;
			m_obTarget.stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMove_obStage);
			m_obTarget.stopDrag() ;
			
		}

	}
}